(function (aopc) {
    aopc.addExpandPage(828, function (get) {
        const Common = get('UtilsCommon', 'Common');

        return {
            expandInit() {
                this.meeting_bg_view = this.getProperty('meeting_bg_view');
                this.contentProperty = this.getViewProperty(this.meeting_bg_view, 'Content');
                this.dialog_content_edit = this.getProperty('dialog_content_edit');

                this.defaultBackImageUrl = 'images/yxinmt_h5/24111120500579060.png';
            },
            setSelfHide({ property, e }) {
                const ele = property.getElement();
                if (ele === e.target) property.setIsVisible(false);
            },
            expandMeetingDataLoad({ data }) {
                this.meetingTitle = data.Title;
            },

            expandGetBackImageLoad({ data }) {
                this.pageData.BackImageId = data.BackImageId;
            },
            expandSetBackImageData({ entityData }) {
                entityData.MeetingId = this.pageData.MeetingId;

                return entityData;
            },
            saveBackImageCallback({ data }) {
                if (data.BackImageId) this.pageData.BackImageId = data.BackImageId;
                this.alertSuccess('保存成功！');
            },
            uploadCallback({ fileUrl, property }) {
                const entityData = {};
                entityData[property.name] = fileUrl;
                entityData.MeetingId = this.pageData.MeetingId;

                const p = property.properties[0];
                const { serviceInterface, saveServiceInterface } = p;

                let serviceName;
                let actionName;
                let url = 'MeetingBackImage';
                if (this.pageData.BackImageId) {
                    serviceName = saveServiceInterface.serviceName;
                    actionName = saveServiceInterface.actionName;
                    url += `(${this.pageData.BackImageId})`;
                }
                else {
                    serviceName = serviceInterface.serviceName;
                    actionName = serviceInterface.actionName;
                }

                this.dispatchAction(serviceName, actionName, { url, MeetingBackImage: entityData }).then(res => {
                    if (res && res.isSuccess !== false) {
                        if (res.BackImageId) this.pageData.BackImageId = res.BackImageId;
                        this.alertSuccess('保存成功！');
                    }
                });
            },
            removeImageUrl({ property, view }) {
                if (property.isLoading) return;
                const entityData = {};
                entityData[view.name] = '';
                entityData.MeetingId = this.pageData.MeetingId;

                const { saveServiceInterface } = property;

                let url = `MeetingBackImage(${this.pageData.BackImageId})`;
                const serviceName = saveServiceInterface.serviceName;
                const actionName = saveServiceInterface.actionName;

                property.isLoading = true;
                this.dispatchAction(serviceName, actionName, { url, MeetingBackImage: entityData }).then(res => {
                    if (res && res.isSuccess !== false) view.setValue('');
                    property.isLoading = false;
                });
            },
            setSelectBackImage({ property, view }) {
                let v = view.getValue();
                if (!v) v = this.defaultBackImageUrl;
                this.setMeetingBackImage(view.getValue());
                this.selectBackImageUrl = view.getValue();
                if (this.theme === 'red') property.style.border = "2rem solid #E40404";
                else property.style.border = "2rem solid #2D60FA";
                view.getView().properties.forEach(p => {
                    if (p.name !== 'save' && p.name !== 'white1') {
                        const img = p.properties[1];
                        if (p.name !== view.name) {
                            img.style.border = "2rem solid #A2ABC0";
                            img.refresh();
                        }
                    }
                });
                property.refresh();
            },
            setMeetingBackImage(url) {
                if (!this.meetingBigScreenData) return;
                this.meetingBigScreenData.BackImageUrl = url;
                this.meeting_bg_view.style.backgroundImage = url
                this.meeting_bg_view.refresh();
            },
            expandGetMeetingBigScreenLoad({ data }) {
                this.meetingBigScreenData = data;
                if (data.BackImageUrl) this.setMeetingBackImage(data.BackImageUrl);

                this.contentProperty.setValue(this.meetingBigScreenData.Content || this.meetingTitle);
                this.setContentFont(data);
            },
            expandSetMeetingBigScreenData({ entityData }) {
                entityData.BackImageUrl = this.meetingBigScreenData.BackImageUrl;
                entityData.MeetingId = this.pageData.MeetingId;

                entityData.Content = this.meetingBigScreenData.Content || this.meetingTitle;
                entityData.FontColor = this.meetingBigScreenData.FontColor;

                if (Common.isNullOrEmpty(entityData.BackImageUrl)) entityData.BackImageUrl = this.defaultBackImageUrl;
                this.meetingBigScreenData = entityData;

                return entityData;
            },
            saveMeetingBigScreenCallback({ props }) {
                const { name } = props.property;
                this.alertSuccess('设置成功！', () => {
                    this.meetingBigScreenData.userId = this.visitUser.UserId;
                    this.webSocket.send('refreshBigScreen', this.meetingBigScreenData);
                    if (name === 'publish2') {
                        this.webSocket.send('syncBigScreen', this.meetingBigScreenData);
                    }
                });

            },
            showContentEdit() {
                const { properties } = this.dialog_content_edit.properties[0];
                this.eventActions.entityEdit.setPropertiesValue(properties, this.meetingBigScreenData);
                this.dialog_content_edit.setIsVisible(true);
            },
            setContentFont(data) {
                const p = this.meeting_bg_view.properties[0];
                p.spanStyle.color = data.FontColor;
                p.setValue(data.Content);
                p.refresh();
            },
            setConentOk() {
                const { properties } = this.dialog_content_edit.properties[0];
                const entityData = this.eventActions.entityEdit.getPropertyValues(properties, this);
                this.meetingBigScreenData.Content = entityData.Content;
                this.meetingBigScreenData.FontColor = entityData.FontColor;

                this.setContentFont(this.meetingBigScreenData);
                this.dialog_content_edit.setIsVisible(false);
            },
            setAllClose() {
                this.webSocket.send('closeBigScreen');
                this.alertSuccess('统一关闭消息已发出');
            },
            setCacheVideos() {
                this.webSocket.send('setCacheVideos', { isShowProgress: true, Title: this.meetingTitle, MeetingId: this.pageData.MeetingId });
                this.alertSuccess('缓存视频消息已发出');
            }
        }
    });
})(window.aopc);